package com.github.authcloud.server.configure;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * @author : zhaoxuan
 * @version : 1.0
 * @date : 2021/8/22 10:53
 * @description : AuthMappingMessageListener
 */
public class  AuthMappingMessageListener {

    private Logger logger = LoggerFactory.getLogger(getClass());

    private RedisTemplate<String, String> authRedisTemplate;

    public AuthMappingMessageListener(RedisTemplate redisTemplate) {
        this.authRedisTemplate = redisTemplate;
    }

    public void listenNoLoginMappingEvent(String serviceName){
        logger.info("AuthCloud--received no login mapping info -- start, from -- {}", serviceName);
        AuthRolePermissionLocalCache.syncNoLoginMappingMap(serviceName, authRedisTemplate);
        logger.info("AuthCloud--received no login mapping info -- end, from -- {}", serviceName);
    }

    public void listenAuthMappingEvent(String serviceName){
        logger.info("AuthCloud--received role and permissions mapping info -- start, from -- {}", serviceName);
        AuthRolePermissionLocalCache.syncRolePermissionMappingMap(serviceName, authRedisTemplate);
        logger.info("AuthCloud--received role and permissions mapping info -- end, from -- {}", serviceName);
    }

}
